{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Main.Housing"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "include(\"housing.jl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "This example uses the [Boston Housing](https://archive.ics.uci.edu/ml/machine-learning-databases/housing) dataset from the UCI Machine Learning Repository to demonstrate a linear regression model. The dataset has housing related information for 506 neighborhoods in Boston from 1978. Each neighborhood has 14 attributes, the goal is to use the first 13, such as average number of rooms per house, or distance to employment centers, to predict the 14’th attribute: median dollar value of the houses.\n",
       "\n",
       "You can run the demo using `julia housing.jl`.  Use `julia housing.jl --help` for a list of options.  The dataset will be automatically downloaded and randomly split into training and test sets.  The quadratic loss for the training and test sets will be printed at every epoch and optimized parameters will be returned.\n"
      ],
      "text/plain": [
       "  This example uses the Boston Housing (https://archive.ics.uci.edu/ml/machine-learning-databases/housing) dataset from the UCI Machine Learning\n",
       "  Repository to demonstrate a linear regression model. The dataset has housing related information for 506 neighborhoods in Boston from 1978. Each\n",
       "  neighborhood has 14 attributes, the goal is to use the first 13, such as average number of rooms per house, or distance to employment centers, to\n",
       "  predict the 14’th attribute: median dollar value of the houses.\n",
       "\n",
       "  You can run the demo using \u001b[36mjulia housing.jl\u001b[39m. Use \u001b[36mjulia housing.jl --help\u001b[39m for a list of options. The dataset will be automatically downloaded and\n",
       "  randomly split into training and test sets. The quadratic loss for the training and test sets will be printed at every epoch and optimized\n",
       "  parameters will be returned."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc Housing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "usage: <PROGRAM> [--seed SEED] [--epochs EPOCHS] [--lr LR]\n",
      "                 [--test TEST] [--atype ATYPE] [--fast]\n",
      "                 [--gcheck GCHECK]\n",
      "\n",
      "housing.jl (c) Deniz Yuret, 2016. Linear regression model for the\n",
      "Housing dataset from the UCI Machine Learning Repository.\n",
      "\n",
      "optional arguments:\n",
      "  --seed SEED      random number seed: use a nonnegative int for\n",
      "                   repeatable results (type: Int64, default: -1)\n",
      "  --epochs EPOCHS  number of epochs for training (type: Int64,\n",
      "                   default: 20)\n",
      "  --lr LR          learning rate (type: Float64, default: 0.1)\n",
      "  --test TEST      ratio of data to split for testing (type: Float64,\n",
      "                   default: 0.0)\n",
      "  --atype ATYPE    array type: Array for cpu, KnetArray for gpu\n",
      "                   (default: \"KnetArray{Float32}\")\n",
      "  --fast           skip loss printing for faster run\n",
      "  --gcheck GCHECK  check N random gradients (type: Int64, default: 0)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "Housing.main(\"--help\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "housing.jl (c) Deniz Yuret, 2016. Linear regression model for the Housing dataset from the UCI Machine Learning\n",
      "Repository.\n",
      "opts=(:fast, false)(:atype, \"KnetArray{Float32}\")(:test, 0.0)(:epochs, 20)(:gcheck, 0)(:lr, 0.1)(:seed, -1)\n",
      "(:epoch, 0, :trn, 589.91534f0, :tst, 589.91534f0)\n",
      "(:epoch, 1, :trn, 365.33887f0, :tst, 365.33887f0)\n",
      "(:epoch, 2, :trn, 240.76071f0, :tst, 240.76071f0)\n",
      "(:epoch, 3, :trn, 162.31473f0, :tst, 162.31473f0)\n",
      "(:epoch, 4, :trn, 112.32275f0, :tst, 112.32275f0)\n",
      "(:epoch, 5, :trn, 80.39411f0, :tst, 80.39411f0)\n",
      "(:epoch, 6, :trn, 59.971302f0, :tst, 59.971302f0)\n",
      "(:epoch, 7, :trn, 46.88646f0, :tst, 46.88646f0)\n",
      "(:epoch, 8, :trn, 38.486275f0, :tst, 38.486275f0)\n",
      "(:epoch, 9, :trn, 33.0798f0, :tst, 33.0798f0)\n",
      "(:epoch, 10, :trn, 29.588388f0, :tst, 29.588388f0)\n",
      "(:epoch, 11, :trn, 27.323427f0, :tst, 27.323427f0)\n",
      "(:epoch, 12, :trn, 25.844942f0, :tst, 25.844942f0)\n",
      "(:epoch, 13, :trn, 24.871622f0, :tst, 24.871622f0)\n",
      "(:epoch, 14, :trn, 24.223448f0, :tst, 24.223448f0)\n",
      "(:epoch, 15, :trn, 23.785141f0, :tst, 23.785141f0)\n",
      "(:epoch, 16, :trn, 23.48279f0, :tst, 23.48279f0)\n",
      "(:epoch, 17, :trn, 23.268978f0, :tst, 23.268978f0)\n",
      "(:epoch, 18, :trn, 23.113214f0, :tst, 23.113214f0)\n",
      "(:epoch, 19, :trn, 22.995876f0, :tst, 22.995876f0)\n",
      "(:epoch, 20, :trn, 22.904295f0, :tst, 22.904295f0)\n",
      "  1.564321 seconds (3.87 M allocations: 201.980 MiB, 5.72% gc time)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2-element Array{Knet.KnetArray{Float32,2},1}:\n",
       " Float32[-0.63893 0.535807 … 0.888601 -3.43639]\n",
       " Float32[22.2739]                              "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Housing.main(\"\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.0.0",
   "language": "julia",
   "name": "julia-1.0"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.0.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
